package br.com.sovi.gwt.client.inicio;

import br.com.sovi.gwt.client.ImagesImpl;
import br.com.sovi.gwt.client.entity.autenticacao.Usuario;
import br.com.sovi.gwt.client.inicio.login.LoginListener;
import br.com.sovi.gwt.client.inicio.login.LoginPanel;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.layout.VerticalLayout;

public class InicioLoginPanel extends Panel implements LoginListener {

	private LoginPanel loginPanel;

	public InicioLoginPanel() {
		this.setLayout(new VerticalLayout(4));
		this.setPaddings(5);
		this.setAutoScroll(true);
		this.setStyleName("inicioLoginPanel");

		this.add(buildHeader());
		this.add(loginPanel = new LoginPanel(this));
	}

	private HTML buildHeader() {
		StringBuffer sb = new StringBuffer();

		sb.append("<div class='inicioLoginPanel_topo'>");
		sb.append(ImagesImpl.get().sovi_topo().getHTML());
		sb.append("</div>");

		return new HTML(sb.toString());
	}

	@Override
	public void onLoginSuccess(Usuario result) {
		loginPanel.limparCampos();
	}

	@Override
	public void onLoginFailed(String string) {
		Window.alert(string);
	}

}
